﻿using IH.Comm.Constant;
using IH.Comm.Dtos;
using IH.Comm.Dtos.MiniApp;
using IH.Comm.Dtos.Users;
using IH.Storage.Entity;
using MongoDB.Driver;
using NAutowired.Core.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IH.Service
{
    [Service]
    public class MiniAppRegService : CoreService
    {
        private IMongoCollection<TMiniAppReg> _miniAppRegCollections => AppStorage.GetCollection<TMiniAppReg>(CollectionsConst.MiniAppReg);
        private IMongoCollection<TMiniAppReadme> _miniAppReadmeCollections => AppStorage.GetCollection<TMiniAppReadme>(CollectionsConst.MiniAppReadme);

        public void SaveMiniAppReg(MiniAppRegSaveInput input, AppUser user)
        {
            var readmeEntity = new TMiniAppReadme()
            {
                Content=input.ReadmeContent,
                Type=(int)input.ReadmeType,
                TypeName= input.ReadmeType.ToString()
            };
            var regEntity = new TMiniAppReg()
            {
                AuthorId=input.AuthorId,
                MiniAppReadmeId=readmeEntity.Id,
                FileUrl=input.FileUrl,
                Mainfest=input.Mainfest,
                UserId=user.UserId
            };

            _miniAppReadmeCollections.InsertOne(readmeEntity);
            _miniAppRegCollections.InsertOne(regEntity);
        }
    }
}
